function insertTitle(path){  
   var test1 = path.lastIndexOf("/");  //对路径进行截取
   var test2 = path.lastIndexOf("\\");  //对路径进行截取
   var test= Math.max(test1, test2);
   if (test < 0) {  
     document.getElementById("test").value = path;
   } else {
    document.getElementById("test").value = path.substring(test + 1); //赋值文件名
   }  
}
function checkPatchVersion(){
	var aa = 0;
	var rowId = $("#rowId").val();
	var gameId = $("#gameId").val();
	var appVersion = $('#appVersion').val();
	var patchVersion = $('#patchVersion').val();
	$.ajax({
		type: "post",
		cache: false,
		url: "/hotUpdate/checkHotUpdate",
		data:{rowId:rowId, gameId:gameId, appVersion:appVersion, patchVersion:patchVersion},
		dataType:"json",
		async:false,
		success: function(data) {
			aa = data;
			if (data == 2) { 
				layer.msg("该app的热更新补丁信息已经存在!");
				return;
			} else {
				//暂无业务
			}
		}
	}); 
	return aa;
}
var flag = $("#flag").val();
//下拉列表显示(app和app版本号)
function selectDo(gameId) {
	if (gameId == "") {
		$(".selectGL").siblings().remove();
		return false;
	}
	var html = "";
	$.ajax({
		type: "post",
		url: "/versionControlLog/select",
		data:{gameId:gameId,flag:0},
		dataType:"json",
		success: function(data) {
	 		$(".selectGL").siblings().remove();
			for (var i=0;i<data.length;i++) {
				 html = '<option value="' +data[i].val+ '">'+ data[i].txt +'</option>';
				 $(".selectGL").after(html);
			}
		}
	});
}

$(function(){ 
	if (flag == 1) {
		$("#gameId").attr("disabled", true);
		//修改操作的时候，文件名称写入input框
		var patchUrl = $("#patchUrl").val();
		var link = patchUrl.substring(patchUrl.lastIndexOf("/")+1, patchUrl.length);
		$("#test").val(link);
	}
});

function add(){ 
	var gameId = $("#gameId").val();
	if (!CheckUtil.isNotNull(gameId)) {
		layer.msg("请选择app!");
		return;
	}
	var appVersion = $('#appVersion').val();
	if (!CheckUtil.isNotNull(appVersion)) {
		layer.msg("请选择app版本号!");
		return;
	}
	var imgPath = $('#imgPath').val();
	if (flag == 0) {
		if (!CheckUtil.isNotNull(imgPath) || (imgPath.indexOf(".ZIP") == -1 && imgPath.indexOf(".zip") == -1)) {
			layer.msg("请选择.zip格式结尾的文件上传!");
			return;
		}
	} else {
		if (CheckUtil.isNotNull(imgPath) && (imgPath.indexOf(".ZIP") == -1 && imgPath.indexOf(".zip") == -1) ) {
			layer.msg("请选择.zip格式结尾的文件上传!");
			return;
		}
	}
	var patchVersion = $('#patchVersion').val();
	if (!CheckUtil.isNotNull(patchVersion) || !CheckUtil.isNumeric(patchVersion)) {
		layer.msg("请输入正确的补丁版本号!");
		return;
	}
	var patchRemark = $('#patchRemark').val();
	if (!CheckUtil.isNotNull(patchRemark)) {
		layer.msg("请输入补丁版本说明!");
		return;
	}
	var rowId = $("#rowId").val();
	var aa = checkPatchVersion();
	if (aa == 2) {
		layer.msg("该app的热更新补丁信息已经存在!");
		return;
	} else if (aa == 1) {
		if ($("#isReCommit").val() == 0) {
			$("#isReCommit").val(1);
			//loading层
			var index = layer.load(0, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
			});
			$("#saveAndUpdateFrom").submit();
		}
	} else {
		//暂无业务
	}
} 